﻿package DevilCat{
	import flash.display.MovieClip ;
	import flash.events.Event;  
	import flash.display.Loader;
	import flash.net.URLRequest; 
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import fl.transitions.TweenEvent; 
	import DevilCat.PokemonObject;
	public class PokemonEventObject extends MovieClip  {
		public var tweenList:Array = new Array();
		public var Pokemon:Array;
		public var pid:Number;
		public var eventLocation:Number=0;
		public var eventNumber:Number=0;
		public function PokemonEventObject(PokemonBase:Array){
			Pokemon=PokemonBase;
			pid=Pokemon[0].pid;
			loadPokemon(pid);
		}
		private function loadPokemon(pid:Number) {
			var imageLoader:Loader = new Loader();
			var imageLink:URLRequest = new URLRequest("http://dex.poke-mega.org/image/pokemon/"+pid+".png");
			imageLoader.load(imageLink);
			imageLoader.contentLoaderInfo.addEventListener(Event.INIT,imageLoaded);
			function imageLoaded(e:Event):void {
				addChild(imageLoader);
			}
		}
		public function setEvent(eventLocationB:Number,eventNumberB:Number){			
			if(eventLocationB>0){
				eventLocation=eventLocationB;
				eventNumber=eventNumberB;			
			}
		}
		public function addMe(){
					tweenList.unshift(new Tween (this,"alpha",Strong.easeOut,0,1,2,true));
					tweenList.unshift(new Tween (this,"y",Strong.easeOut,this.y-50,this.y,2,true));
		}
		public function hitMe(){
					tweenList.unshift(new Tween (this,"alpha",Strong.easeOut,1,0,2,true));
					tweenList.unshift(new Tween (this,"scaleX",Strong.easeOut,1,2,2,true));
					tweenList.unshift(new Tween (this,"scaleY",Strong.easeOut,1,2,2,true));
					tweenList.unshift(new Tween (this,"y",Strong.easeOut,this.y,this.y-50,2,true));
					tweenList.unshift(new Tween (this,"x",Strong.easeOut,this.x,this.x+220,2,true));
					tweenList[0].addEventListener(TweenEvent.MOTION_FINISH,removeMe);
		}
		public function removeMe(e:Event){
			if(this.parent != null){
				this.parent.removeChild(this);
				//trace ("Removed");
			}
		}
	}
}
	